package com.cn.lp.export.client.entity;

import com.cn.lp.export.client.ExportClient;
import com.cn.lp.export.client.base.context.Attributes;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Description: 请描述你的文件
 *
 * @author wuqirong
 * @date 2020-10-21
 * <p>
 * All rights Reserved, Designed www.xiao100.com
 */
@Component
public class DemoExportEventHandler extends ListExportEventHandler<BaseExportInfoParam.ExportDemoConditionVo, DataA, DataAExportVo> {

    @Autowired
    private DataADao dataADao;

    @Autowired
    private ExportClient exportClient;

    /**
     * 导出-导出测试
     */
    @EventListener
    public void exportRevenueVoucherEvent(BaseExportInfoEvent.TestEvent event){
        event.setResult(this.deal(event.getData()));
    }

    protected DemoExportEventHandler() {
        super("测试", DataAExportVo.class);
    }

    @Override
    public Long getTotalCount(BaseExportInfoParam.ExportDemoConditionVo condition, Attributes context) {
        return Long.valueOf(dataADao.countByBid(condition.getQueryCondition().getBid()));
    }

    @Override
    public List<DataA> getVoList(BaseExportInfoParam.ExportDemoConditionVo condition, Integer pageNo, Integer pageSize, Attributes context) {
        PageRequest pageRequest = PageRequest.of(pageNo, pageSize);
        return dataADao.findAllByBid(condition.getQueryCondition().getBid(), pageRequest);
    }

    @Override
    public List<DataAExportVo> format2Sheet(DataA vo, Attributes context) {
        return Lists.newArrayList(new DataAExportVo().setId(vo.getId()).setBid(vo.getBid()));
    }

    @Override
    protected ExportClient getExportClient() {
        return exportClient;
    }
}
